#include "muduo/net/EventLoop.h"
#include "muduo/net/InetAddress.h"

#include "muduo/base/Thread.h"
//release版该头文件是用户不可见的。这里为了测试程序，把源码中的Accept.h拷贝到了当前目录中，并做一些修改。
//不去改动原来的release版本的inc文件夹。
#include "Acceptor.h"
#include <stdio.h>

using namespace muduo;
using namespace muduo::net;

void newConnection(int sockfd, const InetAddress &peerAddr)
{
    printf("newConnection():accepted a new connection from %s\n", peerAddr.toIpPort().c_str());
    ::write(sockfd, "How are you?\n", 13);
    ::close(sockfd);
}

int main()
{
    printf("main():pid=%d\n",getpid());
    InetAddress listenAddr(9981);
    EventLoop loop;
    Acceptor acceptor(&loop,listenAddr,false);
    acceptor.setNewConnectionCallback(newConnection);
    acceptor.listen();
    loop.loop();
    return 1;
}